<template>
  <div class="home-container">
    <!-- 欢迎横幅 -->
    <section class="welcome-banner">
      <div class="banner-content">
        <h1>
          <span class="emoji">👋</span> 
          欢迎, {{ user?.nickname || user?.username }}！
        </h1>
        <p class="subtitle">探索数字藏品的无限可能</p>
      </div>
    </section>

    <!-- 快速状态卡片 -->
    <section class="status-cards">
      <div class="card wallet-card">
        <div class="card-icon">
          <span v-if="user?.walletAddress">✅</span>
          <span v-else>⚠️</span>
        </div>
        <div class="card-content">
          <h3>钱包状态</h3>
          <p v-if="user?.walletAddress" class="status-success">
            {{ formatAddress(user.walletAddress) }}
          </p>
          <p v-else class="status-warning">未绑定钱包</p>
          <router-link v-if="!user?.walletAddress" to="/profile" class="card-link">
            立即绑定 →
          </router-link>
        </div>
      </div>

      <div class="card account-card">
        <div class="card-icon">💎</div>
        <div class="card-content">
          <h3>我的藏品</h3>
          <p class="big-number">{{ nftCount }}</p>
          <router-link to="/my-collections" class="card-link">
            查看详情 →
          </router-link>
        </div>
      </div>

      <div class="card profile-card">
        <div class="card-icon">👤</div>
        <div class="card-content">
          <h3>个人资料</h3>
          <p>{{ user?.email || '未设置邮箱' }}</p>
          <router-link to="/profile" class="card-link">
            编辑资料 →
          </router-link>
        </div>
      </div>
    </section>

    <!-- 快捷操作 -->
    <section class="quick-actions">
      <h2>快捷操作</h2>
      <div class="action-grid">
        <div class="action-card" @click="$router.push('/mint')">
          <div class="action-icon">🎨</div>
          <h3>铸造 NFT</h3>
          <p>创建你的数字藏品</p>
        </div>

        <div class="action-card" @click="$router.push('/')">
          <div class="action-icon">🏪</div>
          <h3>浏览市场</h3>
          <p>发现精彩藏品</p>
        </div>

        <div class="action-card" @click="$router.push('/my-collections')">
          <div class="action-icon">📦</div>
          <h3>我的藏品</h3>
          <p>管理你的收藏</p>
        </div>

        <div class="action-card" @click="$router.push('/profile')">
          <div class="action-icon">⚙️</div>
          <h3>个人设置</h3>
          <p>编辑个人信息</p>
        </div>
      </div>
    </section>

    <!-- 使用指南 -->
    <section class="guide-section" v-if="!user?.walletAddress">
      <div class="guide-card">
        <h2>🚀 快速开始</h2>
        <div class="guide-steps">
          <div class="step">
            <div class="step-number">1</div>
            <div class="step-content">
              <h3>绑定钱包</h3>
              <p>在个人中心绑定你的 MetaMask 钱包</p>
              <router-link to="/profile" class="btn-primary">
                去绑定
              </router-link>
            </div>
          </div>
          <div class="step-divider">→</div>
          <div class="step">
            <div class="step-number">2</div>
            <div class="step-content">
              <h3>铸造 NFT</h3>
              <p>创建你的第一个数字藏品</p>
            </div>
          </div>
          <div class="step-divider">→</div>
          <div class="step">
            <div class="step-number">3</div>
            <div class="step-content">
              <h3>开始交易</h3>
              <p>在市场上买卖你的藏品</p>
            </div>
          </div>
        </div>
      </div>
    </section>
  </div>
</template>

<script>
import { ref, computed, onMounted } from 'vue';
import userStore from '../store/userStore';

export default {
  name: 'Home',
  setup() {
    const user = computed(() => userStore.state.user);
    const nftCount = ref(0);

    const formatAddress = (address) => {
      if (!address) return '';
      return `${address.substring(0, 6)}...${address.substring(address.length - 4)}`;
    };

    onMounted(() => {
      // 这里可以加载用户的NFT数量
      // 暂时显示0
      nftCount.value = 0;
    });

    return {
      user,
      nftCount,
      formatAddress
    };
  }
};
</script>

<style scoped>
.home-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

/* 欢迎横幅 */
.welcome-banner {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 20px;
  padding: 3rem 2rem;
  color: white;
  margin-bottom: 2rem;
  box-shadow: 0 10px 40px rgba(102, 126, 234, 0.3);
}

.banner-content h1 {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.emoji {
  font-size: 1.2em;
}

.subtitle {
  font-size: 1.2rem;
  opacity: 0.9;
}

/* 状态卡片 */
.status-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.card {
  background: white;
  border-radius: 15px;
  padding: 1.5rem;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.card-icon {
  font-size: 2.5rem;
  min-width: 60px;
  text-align: center;
}

.card-content {
  flex: 1;
}

.card-content h3 {
  margin: 0 0 0.5rem 0;
  color: #333;
  font-size: 1.1rem;
}

.card-content p {
  margin: 0.3rem 0;
  color: #666;
}

.status-success {
  color: #67c23a;
  font-weight: 600;
  font-family: 'Courier New', monospace;
}

.status-warning {
  color: #e6a23c;
  font-weight: 600;
}

.big-number {
  font-size: 2rem;
  font-weight: bold;
  color: #667eea !important;
}

.card-link {
  display: inline-block;
  margin-top: 0.5rem;
  color: #667eea;
  text-decoration: none;
  font-weight: 600;
  transition: color 0.3s ease;
}

.card-link:hover {
  color: #764ba2;
}

/* 快捷操作 */
.quick-actions {
  margin-bottom: 2rem;
}

.quick-actions h2 {
  margin-bottom: 1.5rem;
  color: #333;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
}

.action-card {
  background: white;
  border-radius: 15px;
  padding: 2rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.action-card:hover {
  transform: translateY(-8px);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.15);
}

.action-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.action-card h3 {
  margin: 0.5rem 0;
  color: #333;
}

.action-card p {
  margin: 0;
  color: #666;
  font-size: 0.9rem;
}

/* 使用指南 */
.guide-section {
  margin-top: 2rem;
}

.guide-card {
  background: white;
  border-radius: 20px;
  padding: 2rem;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.guide-card h2 {
  text-align: center;
  margin-bottom: 2rem;
  color: #333;
}

.guide-steps {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.step {
  flex: 1;
  min-width: 200px;
  text-align: center;
}

.step-number {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: bold;
  margin: 0 auto 1rem auto;
}

.step-content h3 {
  margin: 0.5rem 0;
  color: #333;
}

.step-content p {
  color: #666;
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.step-divider {
  font-size: 2rem;
  color: #667eea;
  font-weight: bold;
}

.btn-primary {
  display: inline-block;
  padding: 0.6rem 1.5rem;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  text-decoration: none;
  border-radius: 25px;
  font-weight: 600;
  transition: transform 0.3s ease;
}

.btn-primary:hover {
  transform: scale(1.05);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .banner-content h1 {
    font-size: 1.8rem;
  }

  .subtitle {
    font-size: 1rem;
  }

  .step-divider {
    display: none;
  }

  .guide-steps {
    flex-direction: column;
  }
}
</style>

